<template>
	<view class="content" v-if="info.order_sn">
		 <view>
		
		<view class="cu-form-group">
				<view class="title light">状态</view>
				<view class="picker cu-tag round bg-gray light"  v-if="info.status==-1">
					 	己取消
				</view>
				<view class="picker cu-tag round bg-orange light" v-if="info.status==1">
					 	等待接单
				</view>
				<view class="picker cu-tag round bg-blue light" v-if="info.status==2">
					 	商家己接单
				</view>
				 
				<view class="picker cu-tag round bg-green light" v-if="info.status==3">
					 	己完成
				</view>
				<view class="picker cu-tag round bg-green light" v-if="info.status==4">己评价</view>
				
			</view>
			
		<view class="cu-form-group">
				<view class="title light">服务内容</view>
				<view class="picker">
						{{info.title}}
				</view>
				
			</view>
			
		 <view class="cu-form-group" v-if="info.status!=-1">
				<view class="title light">上门地址</view>
				<view class="picker" @click="openAddress">
						{{info.data.address}}
				</view>
				<text class='cuIcon-locationfill text-orange' @click="openAddress"></text>
				
			</view>
			
			<view class="cu-form-group">
				<view class="title light">联系姓名</view>
				<view class="picker">
						{{info.data.name}}
						
				</view>
				
			</view>
			<!--有人接单了，就不显示手机号 -->
			<view class="cu-form-group" v-if="info.status==1 ||  info.provider_shop_id==user_info.user_id">
				<view class="title light">手机号</view>
				<view class="picker" @click="callUserPhone">
						{{info.data.phone}} <text> </text>
						<text class='cuIcon-dianhua text-orange'></text>
				</view>
				
			</view>
			
			
			
			<view class="cu-form-group">
				<view class="title light">创建时间</view>
				<view class="picker">
						{{info.addtime}}
				</view>
				
			</view>
		 
			<view class="cu-form-group">
				<view class="title light">订单号</view>
				<view class="picker">
						{{info.order_sn}}
				</view>
				
			</view>
			
			<view class="cu-form-group" v-if="info.paytime">
				<view class="title light">支付时间</view>
				<view class="picker">
						{{info.paytimeStr}}
				</view>
			</view>

		 </view>
		 <!--显示商家报价信息  -->
		 <view v-if="info.data.provider_name && info.provider_shop_id==user_info.user_id ">
		  <view style=" padding: 20upx;">报价信息</view>
		  <view class="cu-form-group" >
				<view class="title light">报价</view>
				<view class="picker">
						¥ {{info.order_amount}}
				</view>
			</view>
		  <view class="cu-form-group" >
				<view class="title light">联系人</view>
				<view class="picker">
						{{info.data.provider_name}}
				</view>
			</view>
			  <view class="cu-form-group" >
				<view class="title light">手机号</view>
				<view class="picker" @click="callUserProviderPhone">
						{{info.data.provider_phone}}<text class='cuIcon-dianhua text-orange'></text>
				</view>
			</view>
		 </view>
		<view style="height: 120upx;"></view>			
		<!-- 如果有人接单报价，那么显示 -->
		 <view class="fixed-btn"  v-if="info.status==2 && info.provider_shop_id==user_info.user_id" >
				 <view class="cu-bar bg-white tabbar border shop">
				<navigator  :url="'/pages/order/update_price?order_sn='+info.order_sn" class="action" >
					<view class="cuIcon-redpacket text-green"></view>
					修改报价
				</navigator>
				
				<view class="action" @click="cancelOrder">
					<view class="cuIcon-close text-red" ></view>
					取消
				</view>
			 
				<!-- <navigator v-if="info.status==1" :url="'/pages/order/receiving_order?order_sn='+info.order_sn" class="bg-blue submit" >报价接单</navigator> -->
				<navigator :url="'/pages/order/checkout?order_sn='+info.order_sn" class="bg-blue submit" >结算</navigator>
				
			</view>
		</view>
			<!-- 如果没有人接单报价，那么显示1 -->
		<navigator  v-if="info.status==1"  class="fixed-btn cu-btn block bg-blue lg"  :url="'/pages/order/receiving_order?order_sn='+info.order_sn" >报价接单</navigator>
		 
	     
	</view>
</template>
<style>
	.cu-form-group .title{ max-width: 160upx;min-width: 160upx;}
</style>
<script>
	import beeApp from '../../beeApp.js'
	
	export default {
		data() {
			return {
				 
				info:{
					data:{
						
					}
				},
				user_info:{
					
				},
				id:0,
				loadding:0,
				loadding1:0,
			}
		},
		onLoad(option) {
			this.order_sn = option.order_sn;
		    this.getinfo();
			beeApp.getUserInfo((userinfo)=>{
				console.log(userinfo);
				this.user_info = userinfo;
			});
		 
		},
		onShow:function(){
			var reload = beeApp.getPageData("pages/order/detail","reload");
			if(reload==1){
				beeApp.setPageData("pages/order/detail",{reload:0});
				this.getinfo();
			}
		},
		
		onPullDownRefresh() {
			this.getinfo();
			uni.stopPullDownRefresh();
		},
		methods: {
			  openAddress:function(){
				const latitude = this.info.data.latitude;
				const longitude = this.info.data.longitude;
				uni.openLocation({
					latitude: Number(latitude),
					longitude: Number(longitude),
					success: function () {
						console.log('success');
					}
				});
			  },
			  callUserPhone:function(){
				  uni.makePhoneCall({
						phoneNumber: this.info.data.phone  
					});
			  },
			  callUserProviderPhone:function(){
				  uni.makePhoneCall({
						phoneNumber: this.info.data.provider_phone  
					});
			  },
			  cancelOrder:function(){
				   var that = this;
				   if( that.loadding==1){
					   return;
				   }
				   that.loadding=1;
				  uni.showModal({
					title: '提示',
					content: '确认取消订单吗？',
					success: function (res) {
						if (res.confirm) {
							  beeApp.api("/apiv2/dao_jia/cancel",{
								order_sn:that.order_sn,
							},function(res){
								 that.loadding=0;
								 if(res.code!=200){
									beeApp.alert(res.msg);
									return;
								 }
								 beeApp.setPageData("pages/order/list",{reload:1});
								 that.getinfo();
							});
						} else if (res.cancel) {
							console.log('用户点击取消');
							 that.loadding=0;
						}
					}
				});
				 
                   
			  },
			   getinfo:function(){
                    var that = this;
                    beeApp.api("apiv2/order/find",{
                        order_sn:this.order_sn,
                    },function(res){
                         if(res.code!=200){
							beeApp.alert(res.msg);
                            return;
                         }
						 if ( res.data.data){
							  res.data.data = JSON.parse( res.data.data)
						 }
						 that.info = res.data; 
						  
                    });
                },
				
	}
		
}
</script>
